Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve resampling problem for geothermal variable efficiency #1470

Closed
wants to merge 1 commit into from

Conversation

yechenyan
Copy link
Contributor

@yechenyan yechenyan commented Dec 28, 2024

Closes # (if applicable).

Changes proposed in this Pull Request

Resolve resampling problem for geothermal variable efficiency

Problem

When resample is set in wildcards and both enhanced_geothermal and var_cf are enabled, such as in the following configuration:

scenario:
  opts:
  - 2H
  sector_opts:
  - 2H

sector:
  enhanced_geothermal:
    enable: true
    var_cf: true

The code encounters an error because the network snapshots are being resampled to 2-hour intervals, while the geothermal efficiency is still being processed at hourly intervals. This mismatch causes the code to break at line 4546, found here:

efficiency=bus_eta,

The error information is as follows:

INFO:__main__:[EGS] district heat distribution part -> 'geothermal district heat'
INFO:__main__:Adding Enhanced Geothermal with time-varying capacity factors.
INFO:__main__:Adding EGS as Combined Heat and Power.
ERROR:root:Uncaught exception
Traceback (most recent call last):
  File "/Users/Documents/code/pypsa-eur-flexibility/.snakemake/scripts/tmp_gfh6mzl.prepare_sector_network.py", line 4754, in <module>
    add_enhanced_geothermal(
  File "/Users/Documents/code/pypsa-eur-flexibility/.snakemake/scripts/tmp_gfh6mzl.prepare_sector_network.py", line 4542, in add_enhanced_geothermal
    n.add(
  File "/opt/anaconda3/envs/pypsa-eur/lib/python3.12/site-packages/pypsa/components.py", line 1003, in add
    raise ValueError(msg.format(f"DataFrame {k}", "network snapshots"))
ValueError: DataFrame efficiency has an index which does not align with the passed network snapshots.

Fix

Adjust the resampling of geothermal efficiency according to the resample setting specified in wildcards.

Resample may also be gotten from resolution_elec

Checklist

  • I tested my contribution locally and it works as intended.
  • Code and workflow changes are sufficiently documented.
  • Changed dependencies are added to envs/environment.yaml.
  • Changes in configuration options are added in config/config.default.yaml.
  • Changes in configuration options are documented in doc/configtables/*.csv.
  • Sources of newly added data are documented in doc/data_sources.rst.
  • A release note doc/release_notes.rst is added.

@fneum
Copy link
Member

fneum commented Jan 2, 2025

Hi @yechenyan,

The setting:

scenario:
  opts:
  - 2H
  sector_opts:
  - 2H

is invalid and - for sector-coupled models - should be

scenario:
  sector_opts:
  - 2H

In this case, your problem should not occur.

See https://pypsa-eur.readthedocs.io/en/latest/configuration.html#clustering for settings resolution_elec.

@fneum fneum closed this Jan 2, 2025
@yechenyan
Copy link
Contributor Author

hello, @fneum Thank you for your response.

I followed your method for the configuration, but the same error still occurs. I tried to debug, and the error occurs as follows:

  1. Execute the build_egs_potentials rule to generate the egs_capacity_factors_{clusters}.csv This CSV file records data on an hourly basis without resampling. The code is located at:
    capacity_factors = get_capacity_factors(
    snakemake.input["regions"],
    snakemake.input["air_temperature"],
    )
    capacity_factors.to_csv(snakemake.output["egs_capacity_factors"])

Part of the CSV content is as follows:

,DE0 0,DE0 1,DE0 10,DE0 11,DE0 12,DE0 13,DE0 14,DE0 15,DE0 16,DE0 17,DE0 18,DE0 19,DE0 2,DE0 20,DE0 21,DE0 22,DE0 23,DE0 24,DE0 25,DE0 26,DE0 27,DE0 28,DE0 29,DE0 3,DE0 30,DE0 31,DE0 32,DE0 33,DE0 34,DE0 35,DE0 36,DE0 37,DE0 38,DE0 4,DE0 5,DE0 6,DE0 7,DE0 8,DE0 9
2013-01-01 00:00:00,1.0186666677542486,1.0827007150482844,1.0570408631854515,1.0102818745087334,1.0131813440839843,1.0245450004237049,1.0806266795640593,1.0139243443624355,1.0634784837274758,1.1262148597845498,1.0070408144954477,1.0830989671366071,1.0192725032386571,1.09636740394485,1.0470529001000384,1.0300562878110204,1.1074122147319565,1.0139863176024388,1.1315515189920748,1.1068762239498917,1.0295197120748931,1.0691579288042938,1.1065445138238257,1.131248917797728,1.0118760858496665,1.0681680954903108,1.046955472353201,1.065824690460838,1.0393063897467643,1.0555137898826608,1.1250400138522427,1.0066628640314712,1.0312633396312434,1.0528711091024552,1.0088208867315829,1.0735409922240957,1.0443946740398,1.0513439632228136,1.1345890480363836
2013-01-01 01:00:00,1.0200272451720174,1.0861911926338987,1.0597018275358265,1.01303258523309,1.0177858278772398,1.027343722044037,1.0812207041183135,1.0190076213856871,1.0665554156977484,1.1306391595668794,1.0086069356903162,1.0831100737229984,1.0238658574998012,1.0983938341180108,1.04923016776795,1.0320392188011345,1.1093425956410188,1.015819463074386,1.1335611266444934,1.1108552297517886,1.0324462090540498,1.0686859007895917,1.1102358611181613,1.1330809909746138,1.012350217682532,1.069481722195224,1.0472361749544468,1.0640338928836335,1.042376210534257,1.058564748074202,1.126162680456144,1.0075805057580565,1.0328867076842458,1.0531139409681436,1.0101856870328447,1.0752308817987386,1.042924385403023,1.0507370684983892,1.1368020460025299
2013-01-01 02:00:00,1.0213534174745058,1.0859020277386375,1.0572788297730766,1.0155592019177746,1.020949055515006,1.0303144631386023,1.0806826980316202,1.0224331108183322,1.0654541379269795,1.1328251306466173,1.0112144683387199,1.0809593205375547,1.025064351056007,1.0988112562943964,1.0496811116804892,1.032410765241542,1.1106967295795502,1.0182131278931545,1.1358341757200567,1.1120368229441884,1.0356974750785723,1.0677061958674223,1.1136212592442043,1.1345737193122833,1.014353544309988,1.068235833088398,1.0470380171422524,1.061734717945274,1.0414038552299323,1.0598404602768865,1.1277487323097846,1.0096152004252912,1.034674833918711,1.0500111528427227,1.0128641189563692,1.0750557648854766,1.0424846933346892,1.050052264919911,1.1394772517030307
2013-01-01 03:00:00,1.024151262442449,1.0810946836749076,1.0548478929817984,1.015979117161285,1.023110432093673,1.0337958127526374,1.078287897036668,1.0249570632068712,1.064417410805771,1.134320641334097,1.0135502537104888,1.0750290812388303,1.0258614586260426,1.100855419725517,1.05109788466498,1.0325297087993703,1.1138444110135373,1.0188494874748317,1.1381183464270703,1.1111064139910807,1.035211588162775,1.0625242036245026,1.1161713969868121,1.1367716097036884,1.014543741750839,1.0654284908997311,1.046332753305916,1.0587271916500614,1.0415401368246893,1.059016004974814,1.1311121449671868,1.0116550884368123,1.0348584226744644,1.0492720483192075,1.0144940342539175,1.076503556989081,1.0411738068417076,1.049800786568756,1.1435314447098017
2013-01-01 04:00:00,1.025092470398902,1.0801262137564518,1.0575429717254927,1.0165708806814697,1.0275174537238476,1.0378368135095866,1.0788091847978958,1.0280115787768918,1.064268612941719,1.1361075038215351,1.0148638050524663,1.0744203510542496,1.0270724586772655,1.104013089237158,1.0521999318303854,1.0337013046711023,1.1173506114190375,1.0200880022674186,1.140349204734409,1.11184332972745,1.0369026160247499,1.0646216555001293,1.1207746027399588,1.1397227106835013,1.0154488212514747,1.066456497302392,1.047256255043323,1.0594104764955343,1.0463369332450076,1.0592494745977596,1.1342375792368662,1.0139390015332757,1.0323426139909362,1.049274132968184,1.0162843464393914,1.0785053364780155,1.0400164917738741,1.0534729344047362,1.1454293036445085
2013-01-01 05:00:00,1.0289035316348512,1.0732375791411952,1.0575877996627494,1.0195559997076773,1.0314095023430756,1.0406577010526747,1.074892094968412,1.0297241549692195,1.0602750997606454,1.1338520460777723,1.0165465199570696,1.070863239680703,1.028148158045549,1.100617078461569,1.053324145493382,1.0345475395786292,1.117211194348736,1.022672758404301,1.1402997172129028,1.105634052173547,1.0407015271423656,1.0603872865207777,1.116472313623439,1.1401134620327134,1.0177349223628276,1.065219453139519,1.0468434031112717,1.057181055820984,1.049193314710004,1.0587049409692482,1.1326960227085312,1.0167536806323092,1.0337641464940577,1.0497575408684594,1.0194590883347663,1.0777473588894837,1.0403634732935791,1.0564443439620987,1.1429694078618522
  1. In the prepare_sector_network rule, this CSV file is read, and there is no resampling during the reading process. The code can be found at:

    if egs_config["var_cf"]:
    efficiency = pd.read_csv(
    snakemake.input.egs_capacity_factors, parse_dates=True, index_col=0
    )
    logger.info("Adding Enhanced Geothermal with time-varying capacity factors.")

  2. The data from the CSV file is sequentially stored in the variables efficiency and bus_eta, and is used to create geothermal links. There is no resampling in this process either. The code can be found at:

    n.add(
    "Link",
    well_name,
    bus0=spatial.geothermal_heat.nodes,
    bus1=bus1,
    carrier="geothermal heat",
    p_nom_extendable=True,
    p_nom_max=p_nom_max.set_axis(well_name) / efficiency_orc,
    capital_cost=capital_cost.set_axis(well_name) * efficiency_orc,
    efficiency=bus_eta,
    lifetime=costs.at["geothermal", "lifetime"],
    )

Since the resample rate for the network is 2 hours, while the resample rate for bus_eta is 1 hour, an error is triggered. The error is as follows:

INFO:__main__:Adding Enhanced Geothermal with time-varying capacity factors.
INFO:__main__:Adding EGS as Combined Heat and Power.
ERROR:root:Uncaught exception
Traceback (most recent call last):
  File "/Users/Documents/code/pypsa-eur-flexibility/.snakemake/scripts/tmp_gfh6mzl.prepare_sector_network.py", line 4754, in <module>
    add_enhanced_geothermal(
  File "/Users/Documents/code/pypsa-eur-flexibility/.snakemake/scripts/tmp_gfh6mzl.prepare_sector_network.py", line 4542, in add_enhanced_geothermal
    n.add(
  File "/opt/anaconda3/envs/pypsa-eur/lib/python3.12/site-packages/pypsa/components.py", line 1003, in add
    raise ValueError(msg.format(f"DataFrame {k}", "network snapshots"))
ValueError: DataFrame efficiency has an index which does not align with the passed network snapshots.

This is my complete configuration, which can reproduce this issue:

scenario:
  ll:
  - vopt
  clusters:
  - 39
  sector_opts:
  - 2H
  planning_horizons:
  - 2045

countries: ["DE"]

sector:
  enhanced_geothermal:
    enable: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants